<#include "/common/head.html"/>
<table id="dg"></table>
<input type="hidden" id="templateId" name="templateId" value="${id}">
<script type="text/javascript">
	top.window.subPage.save = save;
	var datagrid = $("#dg");

	var dgOptions = {
		fit : true,
		border : false,
		rownumbers : true,
		url : 'templateItemData',
		method : 'post',
		pageSize : 20,
		pagination : true,
		multiSort : true,
		singleSelect : true,
		queryParams : getInitParam(),
		columns : [ [ {
			field : 'id',
			checkbox : false,
			hidden : true
		}, {
			field : 'template_item_name',
			title : '合同名称',
			sortable : true
		}, {
			field : 'template_item_type',
			title : '文件类型',
			sortable : true
		}, {
			field : 'operate',
			title : '操作',
			width : 140,
			frozen : true,
			formatter : function(value, row, index) {
				var html = "";
				html += '<a class="operate" href="templateDownload?id=' + row.id + '">下载模板</a>';
				html += '<a class="operate" href="#" onclick="deleteFile(' + row.id + ')">删除文件</a>';
				return html;
			}
		} ] ],
		loadFilter : function(data) {
			if (data.result && data.result == 'fail') { //失败时，错误消息提示
				showWarnMsg(data.msg);
				return {};
			} else {
				return data;
			}
		}
	};
	$(function() {
		handleAuthDataRule();
		datagrid.datagrid(dgOptions);
	});

	function getInitParam() {
		var param = {};
		param["queryParams[template_id]"] = $("#templateId").val();
		return param;
	}

	function save() {
		top.window.closeWindow();
		top.window.subPage.loadCurrDatagrid();
	}

	function deleteFile(id) {
		$.post("deleteFile", {
			id : id
		}, function(data) {
			showMsg("删除成功！");
			datagrid.datagrid("reload");
		});
	}
</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>